#include "camera_widget.h"
#include "ui_camera_widget.h"
#include<QMessageBox>
#include<QDebug>
camera_Widget::camera_Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::camera_Widget)
{
    ui->setupUi(this);
    m_cameraThread = new CameraThread(this);
    m_cameraThread->setDevice("/dev/video2"); // 根据实际情况修改设备节点

        // 连接信号槽
    connect(m_cameraThread, &CameraThread::frameReady,
                this, &camera_Widget::updateFrame);
    connect(m_cameraThread, &CameraThread::errorOccurred,
                this, &camera_Widget::handleError);

        // 启动摄像头线程

}

camera_Widget::~camera_Widget()
{
    delete ui;
}
void camera_Widget::updateFrame(const QImage &image) {
    // 缩放图像保持比例
    QPixmap pix = QPixmap::fromImage(image)
                  .scaled(ui->label->size(),
                         Qt::KeepAspectRatio,
                         Qt::SmoothTransformation);

    ui->label->setPixmap(pix);
}

void camera_Widget::handleError(const QString &message) {
    QMessageBox::critical(this, "Error", message);
    close();
}
void camera_Widget::on_pushButton_clicked()//打开
{
    m_cameraThread->start();
}



void camera_Widget::on_pushButton_2_clicked()//退出
{
    emit showMenu();
}
